#include "uquerybookwidget.h"
#include "udispbookwidget.h"
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
UQueryBookWidget::UQueryBookWidget(QWidget *parent)
	: QWidget(parent)
	, m_pISBN(new QLabel(this))
	, m_pAuthor(new QLabel(this))
	, m_pTitle(new QLabel(this))
	, m_pISBNEdit(new QLineEdit(this))
	, m_pAuthorEdit(new QLineEdit(this))
	, m_pTitleEdit(new QLineEdit(this))
	, m_pQueryButton(new QPushButton(this))
	, m_pClearButton(new QPushButton(this))
	, m_pDispBookWidget(new UDispBookWidget(this))
{
	setWindowTitle("查询书籍");
	setAttribute(Qt::WA_StyledBackground, true);
	setStyleSheet(R"(UQueryBookWidget{background-color:#F5F5F5;border-radius:4px;border:1px solid #D9D8D7;border:none;})");
	resize(680, 500);

	initLabel();
	initLineEdit();
	initButton();
	connect(m_pQueryButton, &QPushButton::released, this, &UQueryBookWidget::onQueryButtonReleased);
	connect(m_pClearButton, &QPushButton::released, this, &UQueryBookWidget::onClearButtonReleased);

	m_pDispBookWidget->move(15, 90);
}

UQueryBookWidget::~UQueryBookWidget()
{}

void UQueryBookWidget::onQueryButtonReleased()
{
	m_pDispBookWidget->clearWidget();
	if(!m_pISBNEdit->text().isEmpty()|| !m_pAuthorEdit->text().isEmpty()|| !m_pTitleEdit->text().isEmpty())
		UClientServer::Instance()->queryBook(m_pTitleEdit->text(), m_pISBNEdit->text(), m_pAuthorEdit->text());
}

void UQueryBookWidget::onClearButtonReleased()
{
	m_pDispBookWidget->clearWidget();
	m_pISBNEdit->clear();
	m_pAuthorEdit->clear();
	m_pTitleEdit->clear();
}

void UQueryBookWidget::initButton()
{
	QString ButtonStyleSheet = R"(QPushButton{background-color:#808080;border:none;font:#000000;font-family:微软雅黑;font-size: 12px;}
									QPushButton:hover{background-color:#E9E9E9;})";
	m_pQueryButton->resize(60, 25);
	m_pQueryButton->move(430, 55);
	m_pQueryButton->setText("查询");
	m_pQueryButton->setStyleSheet(ButtonStyleSheet);

	m_pClearButton->resize(60, 25);
	m_pClearButton->move(500, 55);
	m_pClearButton->setText("清空");
	m_pClearButton->setStyleSheet(ButtonStyleSheet);
}

void UQueryBookWidget::initLabel()
{
	QString LabelStyleSheet = R"(QLabel{border:none;font:#000000;font-family:微软雅黑;font-size:15px;})";
	m_pTitle->resize(60, 25);
	m_pTitle->move(15, 15);
	m_pTitle->setText("书名:");
	m_pTitle->setStyleSheet(LabelStyleSheet);

	m_pISBN->resize(60, 25);
	m_pISBN->move(350, 15);
	m_pISBN->setText("ISBN:");
	m_pISBN->setStyleSheet(LabelStyleSheet);

	m_pAuthor->resize(60, 25);
	m_pAuthor->move(15, 55);
	m_pAuthor->setText("作者:");
	m_pAuthor->setStyleSheet(LabelStyleSheet);
}

void UQueryBookWidget::initLineEdit()
{
	QString LineEditStyleSheet = R"(QLineEdit{background-color:#FFFFFF;border:none;font:#000000;font-family:微软雅黑;font-size:14px;})";
	m_pTitleEdit->resize(220, 25);
	m_pTitleEdit->move(75, 15);
	m_pTitleEdit->setStyleSheet(LineEditStyleSheet);

	m_pISBNEdit->resize(220, 25);
	m_pISBNEdit->move(410, 15);
	m_pISBNEdit->setStyleSheet(LineEditStyleSheet);

	m_pAuthorEdit->resize(220, 25);
	m_pAuthorEdit->move(75, 55);
	m_pAuthorEdit->setStyleSheet(LineEditStyleSheet);
}

